import { useState } from "react";
import { LIVE_TYPE } from "../../../constants/room";
import { makeFacade, RoomFacade } from "../../../facade/roomFacade";
import { useObservable } from '../../../utils/rxHelpers';

type RoomTuple = [
  RoomFacade,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  Date,
  Date,
  string,
  string,
  boolean,
  string,
  number,
  string, 
];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useRoomFacade(): RoomTuple {
  const [roomFacade] = useState(() => makeFacade());

  const [roomName] = useObservable(roomFacade.roomName$, "");
  const [anchorName] = useObservable(roomFacade.anchorName$, "");
  const [ownerName] = useObservable(roomFacade.ownerName$, "");
  const [ownerId] = useObservable(roomFacade.ownerId$, "");
  const [roomRole] = useObservable(roomFacade.roomRole$, "");
  const [orgName] = useObservable(roomFacade.orgName$, "");
  const [orgLogo] = useObservable(roomFacade.orgLogo$, "");
  const [description] = useObservable(roomFacade.description$, "");
  const [startTime] = useObservable(roomFacade.startTime$, new Date());
  const [endTime] = useObservable(roomFacade.endTime$, new Date());
  const [passwd] = useObservable(roomFacade.passwd$, "");
  const [picUrl] = useObservable(roomFacade.picUrl$, "");
  const [forceSign] = useObservable(roomFacade.forceSignIn$, false);
  const [preLoadVideo] = useObservable(roomFacade.preLoadVideo$, "");
  const [type] = useObservable(roomFacade.type$, LIVE_TYPE.VIDEO);
  const [anchorId] = useObservable(roomFacade.anchorId$, ""); 

  //实在长得让人无力吐槽
  return [
    roomFacade,
    roomName,
    anchorName,
    ownerName,
    ownerId,
    roomRole,
    orgName,
    orgLogo,
    description,
    startTime,
    endTime,
    passwd,
    picUrl,
    forceSign,
    preLoadVideo,
    type,
    anchorId, 
  ];
}
